package com.alit.ibot.manager.attachement;

import com.alit.ibot.manager.attachement.controller.AttachmentURLManager;
import com.alit.ibot.manager.attachement.controller.IndexController;
import com.alit.ibot.manager.attachement.util.IPUtil;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.json.MixedJsonFactory;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;

public class Application extends JFinalConfig {
  public static void main(String[] args) {
    long start = System.currentTimeMillis();
    UndertowServer.start(Application.class);
    long end = System.currentTimeMillis();
    System.out.println("启动完成,共使用了" + (end - start) + "ms");
    printAccessURL();
  }

  private static void printAccessURL() {
    Prop prop = PropKit.use("undertow.txt");
    String ip = IPUtil.getIP();
    String port = prop.get("undertow.port");
    String contextPath = prop.get("undertow.contextPath");
    String accessURL = "http://" + ip + ":" + port + contextPath;
    System.out.println(accessURL);
  }

  public void configConstant(Constants me) {
    me.setInjectDependency(true);
    me.setInjectSuperClass(true);
    me.setJsonFactory(new MixedJsonFactory());
    // me.setDevMode(true);
  }

  public void configRoute(Routes me) {
    me.setMappingSuperClass(true);
    me.add("/", IndexController.class);
    me.add("url_manager", AttachmentURLManager.class);
  }

  public void configEngine(Engine me) {
  }

  public void configPlugin(Plugins me) {
  }

  public void configInterceptor(Interceptors me) {
  }

  public void configHandler(Handlers me) {
  }

}